<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>职位详细信息</title>  
</head>
<body>
<div class="ui segment" id="n-page">
<h3 class="ui header">
${job.name}
</h3>


    <h3 class="ui attached header" id="list-title">
        候选人列表
    </h3>
<c:choose>
    <c:when test="${recommends == null or fn:length(recommends)==0 }">
        &nbsp;<br>该职位还没有任何候选人&nbsp;<br>&nbsp;<br>
    </c:when>
    <c:otherwise>    
    <div class="ui attached segment" id="list-items">
        <c:forEach items="${recommends}" var="rd">
            <div class="ui segment listitem2 position" data-position-id="${rd.id}">
            ${rd.name} ${rd.companyname} ${rd.positionname}<br>
            面试结果：
            <c:choose>
                <c:when test="${rd.status == 0 }">
                    等待邀请
                </c:when>
                <c:when test="${rd.status == 1 }">
                    推荐中
                </c:when>
                <c:when test="${rd.status == 2 }">
                    推荐成功
                </c:when>
                <c:otherwise>
                    推荐失败
                </c:otherwise>
            </c:choose>
            <br>
            </div>
        </c:forEach>        
    </div>
    <br>&nbsp;&nbsp;<br>

    <div class="ui segment" id="btn-next2">
        <div class="fluid ui button" id="next">更多候选人</div>
    </div>
    </c:otherwise>
</c:choose>

    <div class="ui center aligned segment" id="choice-buttons"> 
        <div class="two ui buttons"> 
            <div class="ui button active dog" id="editjob">编辑职位</div> 
            <div class="ui button dog" id="holdjob">Hold职位</div> 
        </div>
    </div>

</div>

<!-- 测试用，正式发布关闭 -->
<!--
<div id="testid">
点击获取更多数据
</div>
-->

<input type="hidden" name="lastperson" id="lastperson" value="${fn:length(recommends)}"/>
<input type="hidden" name="hasmoredata" id="hasmoredata" value="yes"/> 

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'showOptionMenu']  
});

    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 

            if($(this).attr('id') == 'next') {
                datasource.moredata();
            }
            if($(this).attr('id') == 'editjob') {
                location.href = '${ctx}/wechat/hunter/hr/toEditJob.page?positionid='+${job.id};
            }
            if($(this).attr('id') == 'holdjob') {
                var urlHold = '${ctx}/wechat/hunter/hr/holdJobDesc.do?jobid='+${job.id};
                $.ajax({ 
                    url: urlHold, 
                    type: "GET", 
                    success: function(data, status){ 
                        if(data.errorcode == 0) {
                            alert("成功更改职位状态");
                            location.href = '${ctx}/wechat/hunter/hr/joblist.page';
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            location.href = errorUrl;
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                    } 
                });
            }
        } 
    };

    var datasource = { 
        moredata: function() { 
            var getUrl = '${ctx}/wechat/hunter/hr/moreJobRecommend.do?jobid='+${job.id};
            var offset  = $('#lastperson').val();
            var hasmore = $('#hasmoredata').val();

            getUrl += "&offset=" + offset;

            if(hasmore != "yes"){
                alert("已经没有更多数据了");
                return false;
            }
            var that = this;

            $.ajax({ 
                    url: getUrl, 
                    type: "GET", 
                    success: function(data, status){ 
                        if(data.errorcode == 0) {
                            that.appenddata(data);
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            location.href = errorUrl;
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                    } 
            });
        },

        appenddata:function(data) { 
            var offset = parseInt($('#lastperson').val());
            var divstring = "";
            var recommends = data.recommends;

            var count = recommends.length;
            offset += parseInt(count);
            $('#lastperson').val(offset);
            if(count <10) {
                $('#hasmoredata').val('no');
            }

            for (var i in recommends) {
                var rd = recommends[i];

                divstring += '<div class="ui segment listitem2 position" data-position-id="'+ rd.id +'">';
                divstring += rd.name;
                divstring += ' ';
                divstring += rd.companyname;
                divstring += ' ';
                divstring += rd.positionname;
                divstring += '<br>';
                if(rd.status == 0) {
                    divstring += '推荐中';
                } else if(rd.status == 1) {
                    divstring += '推荐成功';
                } else {
                    divstring += '推荐失败';
                }
                divstring += '</div>';
            }

            var newdata = $(divstring);
            $('#list-items').append(newdata);
        }
    };

    $(document).ready(function() { 
        
            $('.button').on('click', handler.activate);
            $('.dropdown').dropdown({
                fullTextSearch:true,
            });

            $('.position').on('click', function() {
                var recommendid = $(this).attr('data-position-id');
                var getUrl = '${ctx}/wechat/hunter/hr/toInterview.do?recommendid='+recommendid;
                location.href = getUrl;
            });
        
            $('#testid').on('click', function(){
                datasource.moredata();
            });
            wx.ready(function() {
<c:choose>
    <c:when test="${job.platformID == 2 }">
            wx.onMenuShareAppMessage({
                title: 'Headoffer--${job.name}--${job.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/sharejob.page?jobid=${job.id}',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: 'Headoffer--${job.name}--${job.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/sharejob.page?jobid=${job.id}',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
            });
    </c:when>
    <c:otherwise>
            wx.onMenuShareAppMessage({
                title: '跳哪里--${job.name}--${job.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com/tn-candidate/wechat/candidate/sharejob.page?jobid=${job.id}',  
                imgUrl: 'http://www.tiaonali.com/tn-candidate/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: '跳哪里--${job.name}--${job.reward} 元',  
                desc: '如果你或者你的朋友符合上面这个职位，那么就推荐给我们。推荐有奖，自荐有奖，奖、奖、奖。',  
                link: 'http://www.tiaonali.com/tn-candidate/wechat/candidate/sharejob.page?jobid=${job.id}',  
                imgUrl: 'http://www.tiaonali.com/tn-candidate/resources/images/sharelogo.jpg'
            });
    </c:otherwise>
</c:choose>


            wx.showOptionMenu();

        });

    });

</script>
</body>
</html>